package homework;

import java.util.List;
import java.util.Stack;

public class HomeWork27 {
    public List<List<Integer>> shiftGrid(int[][] grid, int k) {
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                grid[i][j+1]=grid[i][j];
                grid[i+1][0] =grid[i][j-1];
                grid[0][0]=grid[i-1][j-1];
            }
        }
        return null;
    }
    public int evalRPN(String[] tokens) {
        Stack<Integer>stack=new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            if(tokens[i].equals("+")||tokens[i].equals("-")||tokens[i].equals("*")||tokens[i].equals("/")){
                int b=stack.pop();
                int a=stack.pop();
                if(tokens[i].equals("+")){
                    a+=b;
                    stack.add(a);
                }
                if(tokens[i].equals("-")){
                    a-=b;
                    stack.add(a);
                }
                if(tokens[i].equals("*")){
                    a*=b;
                    stack.add(a);
                }
                if(tokens[i].equals("/")){
                    a/=b;
                    stack.add(a);
                }
                continue;
            }
            stack.add(Integer.parseInt(tokens[i]));
        }
        return stack.pop();
    }
}
